<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="订单号">
              <a-input placeholder="请输入订单号" v-model="queryParam.recordId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="会员">
              <a-input placeholder="请输入会员" v-model="queryParam.allMember"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="充电方式">
                <!--<a-input placeholder="请输入充电方式" v-model="queryParam.chargeMode"></a-input>-->
                <a-select
                  style="width: 100%"
                  placeholder="请输入充电方式"
                  v-model="queryParam.chargeMode">
                  <a-select-option :value="0">刷卡</a-select-option>
                  <a-select-option :value="1">APP</a-select-option>
                  <a-select-option :value="2">管理员</a-select-option>
                  <a-select-option :value="3">微信</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <!--          <a-col :md="6" :sm="8">
                        <a-form-item label="桩号">
                          <a-input placeholder="请输入桩号" v-model="queryParam.pileNumber"></a-input>
                        </a-form-item>
                      </a-col>-->
            <a-col :md="6" :sm="8">
              <a-form-item label="充电桩编码">
                <a-input placeholder="请输入充电桩编码" v-model="queryParam.chargeCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="省">
                <!-- <a-input placeholder="请输入电价" v-model="queryParam.provinceId"></a-input>-->
                <a-select
                  style="width: 100%"
                  placeholder="请输入所属省"
                  v-model="queryParam.provinceId">
                  <a-select-option v-for="(province,provinceindex) in provinceList" :key="provinceindex.toString()" :value="province.id"  @click="queryCityList(province.id)">
                    {{ province.provinceName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="市">
                <!-- <a-input placeholder="请输入市" v-model="queryParam.cityId"></a-input>-->
                <a-select
                  style="width: 100%"
                  placeholder="请输入所属市"
                  v-model="queryParam.cityId">
                  <a-select-option v-for="(city,cityindex) in cityList" :key="cityindex.toString()" :value="city.id" @click="queryDistrictList(city.id)">
                    {{ city.cityName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="区">
                <!-- <a-input placeholder="请输入区" v-model="queryParam.districtId"></a-input>-->
                <a-select
                  style="width: 100%"
                  placeholder="请输入所属区"
                  v-model="queryParam.districtId">
                  <a-select-option v-for="(district,districtindex) in districtList" :key="districtindex.toString()" :value="district.id" @click="chargeSiteListByDistrict(district.id)">
                    {{ district.districtName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="充电站">
                <!-- <a-input placeholder="请输入充电站" v-model="queryParam.chargeSiteCode"></a-input>-->
                <a-select
                  style="width: 100%"
                  placeholder="请输入充电站"
                  v-model="queryParam.chargeSiteCode">
                  <a-select-option v-for="(chargeSite,chargeSiteCodeindex) in chargeSiteList" :key="chargeSiteCodeindex.toString()" :value="chargeSite.id">
                    {{ chargeSite.siteName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
<!--            <a-col :md="6" :sm="8">
              <a-form-item label="结束时间">
                &lt;!&ndash;<a-input placeholder="请输入开始时间" v-model="queryParam.startTime"></a-input>&ndash;&gt;
                &lt;!&ndash;<a-date-picker  format="YYYY-MM-DD HH:mm:ss" v-model="queryParam.startTime" style="width: 100%" placeholder="请输入开始时间"/>&ndash;&gt;
                <j-date v-model="queryParam.startTime" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss" style="width:100%" placeholder="请选择开始时间" ></j-date>
              </a-form-item>
            </a-col>-->
            <a-col :md="6" :sm="8">
              <a-form-item label="结束时间">
                <!--<a-input placeholder="请输入结束时间" v-model="queryParam.endTime"></a-input>-->
                <j-date v-model="queryParam.endTime_begin" :showTime="true" date-format="YYYY-MM-DD 00:00:00" style="width:100%" placeholder="请选择时间范围" ></j-date>

                <!--<a-range-picker
                  style="width: 210px"
                  v-model="queryParam.endTimeRange"
                  format="YYYY-MM-DD HH:mm:ss"
                  :placeholder="['开始时间', '结束时间']"
                  @change="onDateChange"
                  @ok="onDateOk"
                />-->
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="至">
                <j-date v-model="queryParam.endTime_end" :showTime="true" date-format="YYYY-MM-DD 00:00:00" style="width:100%" placeholder="请选择时间范围" ></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('充电记录')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="chargeMode" slot-scope="text, record, index">
          <div class="anty-img-wrap" >
            <a>{{chargeModeName(record.chargeMode)}}</a>
          </div>
        </template>
        <template slot="gunType" slot-scope="text, record, index">
          <div class="anty-img-wrap" >
            <a >{{gunTypeName(record.gunType)}}</a>
          </div>
        </template>
        <template slot="startSoc" slot-scope="text, record, index">
          <div class="anty-img-wrap" >
            <a >{{soc(record.startSoc)}}</a>
          </div>
        </template>
        <template slot="endSoc" slot-scope="text, record, index">
          <div class="anty-img-wrap" >
            <a >{{soc(record.endSoc)}}</a>
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <wxcChargingRecord-modal ref="modalForm" @ok="modalFormOk"></wxcChargingRecord-modal>
  </a-card>
</template>

<script>
  import WxcChargingRecordModal from './modules/WxcChargingRecordModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { postAction } from '@/api/manage'
  import JDate from '@/components/jeecg/JDate'
  export default {
    name: "WxcChargingRecordList",
    mixins:[JeecgListMixin],
    components: {
      WxcChargingRecordModal,
      JDate
    },
    data () {
      return {
        description: '充电记录管理页面',
        chargeSiteList:[],
        provinceList:[],
        cityList:[],
        districtList:[],
        // 查询条件
        queryParam: {
          endTimeRange:[],
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '订单号',
            align:"center",
            dataIndex: 'recordId'
          },
          {
            title: '会员',
            align:"center",
            dataIndex: 'allMember'
          },
          {
            title: '充电方式',
            align:"center",
            dataIndex: 'chargeMode',
            scopedSlots: {customRender: "chargeMode"}
          },
          {
            title: '桩号',
            align:"center",
            dataIndex: 'pileNumber'
          },
          {
            title: '充电桩编码',
            align:"center",
            dataIndex: 'chargeCode'
          },
          {
            title: '桩类型',
            align:"center",
            dataIndex: 'gunType',
            scopedSlots: {customRender: "gunType"}
          },
          {
            title: '充电时长',
            align:"center",
            dataIndex: 'duration'
          },
          {
            title: '充电度数',
            align:"center",
            dataIndex: 'quantity'
          },
          {
            title: '充电金额',
            align:"center",
            dataIndex: 'amount'
          },
          {
            title: '开始时间',
            align:"center",
            dataIndex: 'startTime'
          },
          {
            title: '结束时间',
            align:"center",
            dataIndex: 'endTime'
          },

          {
            title: '充电策略',
            align:"center",
            dataIndex: 'chargePolicy'
          },
          {
            title: '充电策略参数',
            align:"center",
            dataIndex: 'chargePolicyParam'
          },
          {
            title: '开始SOC',
            align:"center",
            dataIndex: 'startSoc',
            scopedSlots: {customRender: "startSoc"}
          },
          {
            title: '结束SOC',
            align:"center",
            dataIndex: 'endSoc',
            scopedSlots: {customRender: "endSoc"}
          },
          {
            title: '结束原因编码',
            align:"center",
            dataIndex: 'endReasonCode'
          },
          {
            title: '结束原因',
            align:"center",
            dataIndex: 'endReason'
          },
          {
            title: '结束原因描述',
            align:"center",
            dataIndex: 'endReasonDescription'
          },
          {
            title: '充电前余额',
            align:"center",
            dataIndex: 'beforeBalance'
          },
          {
            title: '充电后余额',
            align:"center",
            dataIndex: 'afterBalance'
          },
          /*{
               title: '车辆VIN',
               align:"center",
               dataIndex: 'vehicleVin'
              },
              {
               title: '成本',
               align:"center",
               dataIndex: 'costPrice'
              },
              {
               title: '利润',
               align:"center",
               dataIndex: 'profit'
              },
              {
               title: '是否删除',
               align:"center",
               dataIndex: 'delFlag'
              },*/
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/wxcchargingrecord/wxcChargingRecord/list",
          delete: "/wxcchargingrecord/wxcChargingRecord/delete",
          deleteBatch: "/wxcchargingrecord/wxcChargingRecord/deleteBatch",
          exportXlsUrl: "wxcchargingrecord/wxcChargingRecord/exportXls",
          importExcelUrl: "wxcchargingrecord/wxcChargingRecord/importExcel",
          provinceListUrl:"/dictionary/dictionary/provinceList",
          cityListUrl:"/dictionary/dictionary/cityList",
          districtListUrl:"/dictionary/dictionary/districtList",
          chargeSiteListUrl:"/wxcchargingsite/wxcChargingSite/siteListByDistrict",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      this.queryProvinceList();
      this.queryCityList();
      this.queryDistrictList();
      this.chargeSiteListByDistrict();
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      chargeModeName(chargeMode){
        if(chargeMode==0){
          return "刷卡"
        }else if(chargeMode ==1){
          return "APP"
        }else if(chargeMode ==2){
          return "管理员"
        }else if(chargeMode ==3){
          return "微信"
        }else{
          return "其他"
        }
      },
      gunTypeName(gunType){
        if(gunType ==1){
          return "直流"
        }else if(gunType ==2){
          return "交流"
        }else{
          return "其它"
        }
      },
      soc(soc){
        if(soc !=null){
          return soc+"%"
        }else{
          return 0+"%"
        }
      },
      queryProvinceList(){
        postAction(this.url.provinceListUrl).then((res)=>{
          if(res.success){
            this.provinceList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      queryCityList(provinceId){
        let params = {provinceId:provinceId}
        postAction(this.url.cityListUrl,params).then((res)=>{
          if(res.success){
            this.cityList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      queryDistrictList(cityId){
        let params = {cityId:cityId}
        postAction(this.url.districtListUrl,params).then((res)=>{
          if(res.success){
            this.districtList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      chargeSiteListByDistrict(districtId){
        let params = {districtId:districtId}
        postAction(this.url.chargeSiteListUrl,params).then((res)=>{
          if(res.success){
            this.chargeSiteList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err)=>{
          this.$message.error("请求异常："+err)
        })

      },
      onDateChange: function (value, dateString) {
        console.log(dateString[0],dateString[1]);
        this.queryParam.endTime_begin=dateString[0];
        this.queryParam.endTime_end=dateString[1];
      },
      onDateOk(value) {
        console.log(value);
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>